package com.freak.kotlinfitnessserver.activity.adapter

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.freak.kotlinfitnessserver.activity.fragment.DeviceInfoFragment
import com.freak.kotlinfitnessserver.activity.fragment.FitnessMachineFeaturesFragment
import com.freak.kotlinfitnessserver.activity.fragment.SupportedRangeFragment
import com.freak.kotlinfitnessserver.activity.fragment.TargetSettingFeaturesFragment


/**
 * 页面适配器 page/tag/fragment
 * @author freak
 * @since 2024-01-24
 */
class SectionsPagerAdapter(
    private val context: Context,
    fm: FragmentManager,
    deviceType: String
) :
    FragmentPagerAdapter(fm) {

    private val FITNESS_TAB_TITLES = arrayOf(
        "DeviceInfo",
        "FitnessMachineFeatures",
        "TargetSettingFeatures",
        "SupportedRange"
    )

    private val FITNESS_FRAGMENT_LIST = arrayOf(
        DeviceInfoFragment.newInstance(deviceType),
        FitnessMachineFeaturesFragment.newInstance(deviceType),
        TargetSettingFeaturesFragment.newInstance(deviceType),
        SupportedRangeFragment.newInstance(deviceType),
    )

    override fun getItem(position: Int): Fragment {
        return FITNESS_FRAGMENT_LIST[position]
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return FITNESS_TAB_TITLES[position]
    }

    override fun getCount(): Int {
        return FITNESS_TAB_TITLES.size
    }
}